<?php
require 'weixin.config.php';

$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;
$content=file_get_contents($url);
$ret=json_decode($content,true);
$access_token=$ret['access_token'];
function curl_post($url,$data){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $tmpInfo = curl_exec($curl);
    if (curl_errno($curl)) {
        echo 'Errno'.curl_error($curl);
    }
    curl_close($curl);
    return $tmpInfo;
}
$data='{"button":[
{"type":"view","name":"首页","url":"http://www.welcom212.com/m"},
{"name":"小功能",
  "sub_button":[
     {
       "type":"click",
       "name":"生成二维码",
       "url":"http://www.welcom212.com/m/wxapi/getcode.php"
     },
     {
       "type":"click",
       "name":"开发中...",
       "key":"develop"
     }
  ]
},
{"type":"view","name":"我的github","url":"https://github.com/meijhm"}

]}';
$url='https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$access_token;

$content=curl_post($url,$data);
$result=json_decode($content,true);
if( $result["errmsg"]==0){
    echo '<h2>菜单创建成功</h2>';
};